package com.runen.wnhz.runen.presenter.iPresenter;

import android.util.Log;

import com.runen.wnhz.runen.data.entity.BaseEntity;
import com.runen.wnhz.runen.data.entity.ShopDetail;
import com.runen.wnhz.runen.data.entity.ShopInfo;
import com.runen.wnhz.runen.data.entity.ShopListEntity;
import com.runen.wnhz.runen.data.entity.ShopTypeEntity;
import com.runen.wnhz.runen.presenter.BasePresenter;
import com.runen.wnhz.runen.presenter.Contart.PublicmContart;
import com.runen.wnhz.runen.presenter.model.PublicmModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/5/31 0031.
 */

public class IPublicmPresenter extends BasePresenter<PublicmModel, PublicmContart.View> {

    @Inject
    public IPublicmPresenter(PublicmModel mModel, PublicmContart.View mView) {
        super(mModel, mView);
    }

    public void getShopList() {
        Map<String, String> map = new HashMap<>();
        map.put("token", mView.getToken());
        map.put("type_id", mView.getTypeId());
        map.put("sdate", mView.getSdate());
        map.put("edate", mView.getEdate());
        map.put("page", mView.getpageNum());
        mModel.getShopList(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseEntity<ShopListEntity<List<ShopInfo>>>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(BaseEntity<ShopListEntity<List<ShopInfo>>> baseEntity) {
                        Log.d("result", "-----onNext----");
                        Log.d("IPublicmPresenter", baseEntity.toString());
                        mView.updateShopList(baseEntity);
                    }

                });
    }

    public void getShoptype() {
        Map<String, String> map = new HashMap<>();
        if(null != mView.getToken() && !mView.getToken().equals("")){
            map.put("token", mView.getToken());
        }

        mModel.getShopType(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseEntity<List<ShopTypeEntity>>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(BaseEntity<List<ShopTypeEntity>> listBaseEntity) {
                        Log.d("IPublicmPresenter", listBaseEntity.toString());
                        if (null != listBaseEntity) {
                            mView.saveShopeTypeList(listBaseEntity);
                        }
                    }
                });
    }

   
}
